package com.hernandez.games.adventures.controllers;

import com.hernandez.games.adventures.beans.GameStatus;
import com.hernandez.games.adventures.events.GameStatusChangedEvent;
import com.hernandez.games.adventures.events.IEventHandler;
import com.hernandez.games.adventures.events.TickEvent;

public class CPUTickController implements IController, IEventHandler<GameStatusChangedEvent>{
	private boolean keepRunning = false;
	public CPUTickController() {
		EventController.getInstance().registerHandler(GameStatusChangedEvent.class, this);
	}

	public void run() {
		while(keepRunning)
			EventController.getInstance().publishEvent(TickEvent.newEvent());
	}

	@Override
	public void publishEvent(GameStatusChangedEvent event) {
		keepRunning = event.getGameStatus() != GameStatus.EXITING;
	}
	
}
